
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
// import createPersistedState from 'vuex-persistedstate'


const store = new Vuex.Store({
    // plugins:[new createPersistedState({
    //     storage:window.sessionStorage
    // })],
    state: {
        // 初始化状态
        count: 0,
        feature:[
            'aa','bb','cc','dd','index'
        ]
    },
    mutations: {
        // 处理状态
        increment(state, payload) {
            state.count += payload.step || 1;
        }
    },
    actions: {
        // 提交改变后的状态
        increment(context, param) {
            context.state.count += param.step;
            context.commit('increment', context.state.count)//提交改变后的state.count值
        },
        incrementStep({state, commit, rootState}) {
            if (rootState.count < 100) {
                store.dispatch('increment', {//调用increment()方法
                    step: 10
                })
            }
        }
    }
});

export default store;